import { deleteByPrimaryKeyForProDept, selectByPrimaryKeyForProDept, insertForProDept, updateForProDept, deleteByMapForProDept,updateByMapForProDept, getOneForProDept,getAllForProDept,queryPageForProDept, countForProDept, insertBatchForProDept, deleteBatchForProDept,updateBatchForProDept,getProDeptTreeByParentid } from '@/services/system/api_prodept';

export default {
    namespace: 'prodept',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        selectDeptTree: {
        	list:[],
        },
    },

    effects: {
            *delete_by_primarykey_for_prodept({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProDept, payload);
								
				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProDept, newPayload);
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });
								
				if (callback) callback(response);

            },
            *select_by_primarykey_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProDept, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProDept',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(insertForProDept, payload);

                const responsedata = yield call(queryPageForProDept, {});
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *update_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(updateForProDept, payload);
								
				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProDept, newPayload);
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *delete_by_map_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProDept, payload);
                yield put({
                    type: 'deleteByMapForProDept',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDept, {});
                yield put({
                type: 'queryPageForProDept',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProDept, payload);
                yield put({
                    type: 'updateByMapForProDept',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDept, {});
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProDept, payload);
                yield put({
                    type: 'getOneForProDept',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_all_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProDept, payload);
                yield put({
                    type: 'getAllForProDept',
                    payload: response,
                });

                if (callback) callback();
            },
            *query_page_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProDept, payload);
                yield put({
                    type: 'queryPageForProDept',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(countForProDept, payload);
                yield put({
                    type: 'countForProDept',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProDept, payload);
                yield put({
                    type: 'insertBatchForProDept',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDept, {});
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProDept, payload);
                yield put({
                    type: 'deleteBatchForProDept',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProDept, {});
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProDept, payload);
                yield put({
                    type: 'updateBatchForProDept',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProDept, {});
                yield put({
	                type: 'queryPageForProDept',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_prodepttree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getProDeptTreeByParentid, payload);
                yield put({
                    type: 'getProDeptTreeByParentid',
                    payload: response,
                });

                if (callback) callback(response);
            },
    },

    reducers: {
        deleteByPrimaryKeyForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getProDeptTreeByParentid(state, action) {
            return {
                ...state,
                selectDeptTree: action.payload,
            };
        },
    },
};
